package com.pet.admin.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.pet.admin.service.AdLaberService;
import com.pet.apis.admin.LaberController.AdLaberControllerApi;
import com.pet.model.admin.dtos.LaberDto;
import com.pet.model.admin.pojos.AdLaber;
import com.pet.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/label")
public class AdLaberController implements AdLaberControllerApi {

    @Autowired
    private AdLaberService adLaberService;

    @PostMapping("/list")
    @Override
    public ResponseResult findByNameAndPage(@RequestBody LaberDto dto) {
        return adLaberService.findByNameAndPage(dto);
    }

    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody AdLaber adLaber) {
        return adLaberService.insert(adLaber);
    }

    @PostMapping("/update")
    @Override
    public ResponseResult update(@RequestBody AdLaber adLaber) {
        return adLaberService.update(adLaber);
    }

    @GetMapping("/del/{id}")
    @Override
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return adLaberService.deleteById(id);
    }

    @GetMapping("/labers")
    @Override
    public ResponseResult findAll() {
        LambdaQueryWrapper<AdLaber> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(AdLaber::getStatus, true);
        List<AdLaber> list = adLaberService.list(lambdaQueryWrapper);
        return ResponseResult.okResult(list);
    }
}
